﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace FitterTest.Filters
{
    public class CtmActionFilter2Attribute : ActionFilterAttribute
    {
        //private readonly ILogger<CtmActionFilter2Attribute> logger;

        //public CtmActionFilter2Attribute(ILogger<CtmActionFilter2Attribute> logger)
        //{
        //    this.logger = logger;
        //}
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            var logger = context.HttpContext.RequestServices.GetService<ILogger<CtmActionFilter2Attribute>>();
            logger?.LogWarning($"Action{context.ActionDescriptor.DisplayName} 执行完毕");
            base.OnActionExecuted(context);
        }

        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var logger = context.HttpContext.RequestServices.GetService<ILogger<CtmActionFilter2Attribute>>();
            logger?.LogWarning($"Action{context.ActionDescriptor.DisplayName} 当前执行");
            base.OnActionExecuting(context);
        }
    }
}
